<template>
  <div class="nav-header">
    <i
      class="fold-menu"
      :class="isfold ? 'el-icon-s-fold' : 'el-icon-s-unfold'"
      @click="handleFoldClick"
    ></i>
    <div class="content">
      <cy-breadcrumb :breadcrumbs="breadcrumbs" />
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import UserInfo from './user-info.vue'
import CyBreadcrumb, { IBreadcrumb } from '@/base-ui/breadcrumb'

import { useStore } from '@/store'
import { useRoute } from 'vue-router'
import { pathMapbreadcrumbs } from '@/utils/map-menus'

export default defineComponent({
  components: { UserInfo, CyBreadcrumb },

  emits: ['foldChange'],

  setup(props, { emit }) {
    const isfold = ref(false)

    const handleFoldClick = () => {
      isfold.value = !isfold.value
      emit('foldChange', isfold.value)
    }

    // 面包屑的数据  [{name: , path:}]
    const store = useStore()

    const breadcrumbs = computed(() => {
      const userMenus = store.state.login.userMenus
      const route = useRoute()
      const currentRoute = route.path
      return pathMapbreadcrumbs(userMenus, currentRoute)
    })

    return {
      isfold,
      handleFoldClick,
      breadcrumbs
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    // 占据剩余部分
    flex: 1;
    padding: 0 20px;
  }
}
</style>
